#ifndef PAGES
#define PAGES

#include "typedef.hpp"

// 枚举值定义
enum META
{
	Dirty = 1,
	Valid = 2,
	Cache_EN = 4,
	IsChild = 8,
	Is_IO = 16
};

// 页表项
using PTE = std::tuple<uint64_t, uint8_t, uint8_t>; // PPE,Access,Meta
uint64_t to_uint64(PTE pte);

class TLB
{
private:
	std::tuple<uint64_t, uint64_t, PTE> *table; // tag,PADDR,PTE
	MessageBus *bus;
	std::pair<uint64_t, uint64_t> PRegs[3];

public:
	TLB() :table(nullptr), bus(nullptr) {}
	TLB(MessageBus *bus);
	~TLB() = default;
	void translate();
	void update();
	void store(int index);
	void flush();
	void run();
};

#endif